<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>添加</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
    <div style="margin: 20px">
        <div><span>姓名</span><input type="text" id="name" /></div>
        <div><span>语文</span><input type="text" id="yuwen" /></div>
        <div><span>数学</span><input type="text" id="shuxue" /></div>
        <div><span>英语</span><input type="text" id="yingyu" /></div>
        <div><span>历史</span><input type="text" id="lishi" /></div>
        <div><span>地理</span><input type="text" id="dili" /></div>
        <div><span>政治</span><input type="text" id="zhengzhi" /></div>
        <div><span>物理</span><input type="text" id="wuli" /></div>
        <div><span>化学</span><input type="text" id="huaxue" /></div>
        <div><span>生物</span><input type="text" id="shengwu" /></div>
        <div><span>体育</span><input type="text" id="tiyu" /></div>

        <div><button id="submit">提交</button></div>
    </div>
</body>
</html>

<script>
    //点击button按钮处理
    $("#submit").click(function(){
        var name = $("#name").val();
        if (name==null || name==''){
            alert("姓名不能为空")
            return false;
        }
        var yuwen = $("#yuwen").val();
        if (yuwen==null || yuwen==''){
            alert("语文不能为空")
            return false;
        }
        var shuxue = $("#shuxue").val();
        if (shuxue==null || shuxue==''){
            alert("数学不能为空")
            return false;
        }
        var yingyu = $("#yingyu").val();
        if (yingyu==null || yingyu==''){
            alert("英语不能为空")
            return false;
        }
        var lishi = $("#lishi").val();
        if (lishi==null || lishi==''){
            alert("历史不能为空")
            return false;
        }
        var dili = $("#dili").val();
        if (dili==null || dili==''){
            alert("地理不能为空")
            return false;
        }
        var zhengzhi = $("#zhengzhi").val();
        if (zhengzhi==null || zhengzhi==''){
            alert("政治不能为空")
            return false;
        }
        var wuli = $("#wuli").val();
        if (wuli==null || wuli==''){
            alert("物理不能为空")
            return false;
        }
        var huaxue = $("#huaxue").val();
        if (huaxue==null || huaxue==''){
            alert("化学不能为空")
            return false;
        }
        var shengwu = $("#shengwu").val();
        if (shengwu==null || shengwu==''){
            alert("生物不能为空")
            return false;
        }
        var tiyu = $("#tiyu").val();
        if (tiyu==null || tiyu==''){
            alert("体育不能为空")
            return false;
        }
        $.ajax({
            url: "/result/add",// The URL for the request
            contentType : "application/json",
            data: JSON.stringify({name:name, yuwen: yuwen, shuxue: shuxue, yingyu: yingyu, lishi: lishi, dili: dili, zhengzhi: zhengzhi, wuli: wuli, huaxue: huaxue,shengwu:shengwu,tiyu:tiyu}),
            type: "POST",// Whether this is a POST or GET request
        }).done(function(res) {
            if (res.code==200){
                alert("添加成功")
                location.href = "index"
            } else {
                alert(res.message);
            }
        });
    })
</script>
<style>
    span{
        font-size: 18px;
        margin-right: 10px;
        margin-top: 5px;
    }
    input{
        line-height: 32px;
        font-size: 20px;
        margin-top: 5px;
    }
    #submit{
        margin-top: 20px;
        line-height: 28px;
        width: 80px;
        color: #67C23A;
    }
</style>